/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LEBean;
import com.postek.coyote.postekwifi.bean.LOBean;
import com.postek.coyote.postekwifi.bean.LWBean;
import com.postek.coyote.postekwifi.bean.LabelBean;

import java.util.ArrayList;

/**
 * @author yrwang
 *
 */
public class PrintLE_LO_LWActivity extends AppCompatActivity {

	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	
	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private EditText et_p1 = null;
	private EditText et_p2 = null;
	private EditText et_p3 = null;
	private EditText et_p4 = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_le);
		
		btnPrint = (Button) findViewById(R.id.btn_printLE_print);
		btnCancel = (Button) findViewById(R.id.btn_printLE_cancel);
		
		et_p1 = (EditText) findViewById(R.id.et_print_LE1);
		et_p2 = (EditText) findViewById(R.id.et_print_LE2);
		et_p3 = (EditText) findViewById(R.id.et_print_LE3);
		et_p4 = (EditText) findViewById(R.id.et_print_LE4);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);

		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iLE1 = 0;
				int iLE2 = 0;
				int iLE3 = 0;
				int iLE4 = 0;
				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());
				
				if(!("".equals(et_p1.getText().toString()))){
					iLE1 = Integer.parseInt(et_p1.getText().toString());
				}
				
				if(!("".equals(et_p2.getText().toString()))){
					iLE2 = Integer.parseInt(et_p2.getText().toString());
				}
				
				if(!("".equals(et_p3.getText().toString()))){
					iLE3 = Integer.parseInt(et_p3.getText().toString());
				}
				
				if(!("".equals(et_p4.getText().toString()))){
					iLE4 = Integer.parseInt(et_p4.getText().toString());
				}
				
				Intent intent = PrintLE_LO_LWActivity.this.getIntent();
				String str = intent.getStringExtra("Order");
				
				int nReturn = 0;
				
				if(str.equals("LE")){
					nReturn = cdf.PTK_DrawLineXor(iLE1, iLE2, iLE3, iLE4);
				} else if (str.equals("LO")) {
					nReturn = cdf.PTK_DrawLineOr(iLE1, iLE2, iLE3, iLE4);
				} else if (str.equals("LW")) {
					nReturn = cdf.PTK_DrawWhiteLine(iLE1, iLE2, iLE3, iLE4);
				}
				
				if (nReturn == 0) {
					if(str.equals("LE")){
						LEBean bean = new LEBean(iLE1, iLE2, iLE3, iLE4);
						labelBeans.add(bean);
					} else if (str.equals("LO")) {
						LOBean bean = new LOBean(iLE1, iLE2, iLE3, iLE4);
						labelBeans.add(bean);
					} else if (str.equals("LW")) {
						LWBean bean = new LWBean(iLE1, iLE2, iLE3, iLE4);
						labelBeans.add(bean);
					}
					Toast.makeText(PrintLE_LO_LWActivity.this,  R.string.setting_success, Toast.LENGTH_SHORT).show();
					cdf.PTK_PrintLabel(number,cpnumber);
				} else {
					Toast.makeText(PrintLE_LO_LWActivity.this,  R.string.setting_fail, Toast.LENGTH_SHORT).show();
				}
			}
		});
	}

}
